<template>
  <el-row class="tac">
    
    <el-col :span="24">
      <!-- <h5 class="mb-2">Custom colors</h5> -->
      <el-menu
        active-text-color="#ffd04b"
        background-color="#545c64"
        class="el-menu-vertical-demo"
        default-active="1"
        text-color="#fff"
        @select="handleOpen"
 
		@click="onHand"
      >
        <el-sub-menu  index="1">
          <template  #title>
            <el-icon><Document /></el-icon>
            <span >全部图书</span>
          </template>
			<!-- 子 -->
            <el-menu-item index="1-1">编程</el-menu-item>
            <el-menu-item index="1-2">文学</el-menu-item>
        </el-sub-menu>
		
        <el-menu-item index="2" v-show="myadmin">
          <el-icon><icon-menu /></el-icon>
          <span>图书管理</span>
        </el-menu-item>
        <el-menu-item index="3" >
          <el-icon><location /></el-icon>
          <span>我的借阅</span>
        </el-menu-item>
        <el-menu-item index="4">
          <el-icon><setting /></el-icon>
          <span>个人信息</span>
        </el-menu-item>
      </el-menu>
    </el-col>
  </el-row>
</template>

<script lang="ts" setup>
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'

import {  onMounted, ref } from 'vue';
import mitt from '../utils/mitt';
 
const emit = defineEmits(['get-message','get-index','get-flash','get-msg'])
const index = ref('')


//子传父
const sendMsg = (msg,index) =>{
	emit('get-message',msg)
	emit('get-index',index)
	
}
const myadmin=ref(true)
onMounted(()=>{
	
	onHidden()
})
const onHidden=()=>{
	if(localStorage.getItem('utype')=='0'){
		myadmin.value=true
	}else{
		myadmin.value=false
	}
}
const handleOpen = (key: string, keyPath: string[]) => {
	index.value=key
	//console.log(key+'shuzi', keyPath)
}
// const handleClose = (key: string, keyPath: string[]) => {
// 	index.value=key
// 	//console.log(index.value)
// 	console.log(key, keyPath)
// }


const onHand=(e)=>{
	if(localStorage.getItem('name')==null){
		emit('get-msg',"请先登录")
	}
	
	if(index.value.includes('-')){
		emit('get-msg',"暂未实现分类")
		sendMsg("全部图书",e.target.innerText)
		return
	}
	sendMsg(e.target.innerText,'')
	index.value=''
	let data="flash"
	mitt.emit('myMsg',data)
	//console.log(e.target.innerText)
}

defineExpose({
	onHidden
})

</script>
<style>
	
</style>
